import request from '@/utiles/request.js'

export const userRegisterService = async ( nickname,phone, password ) => {
  // 返回响应的数据
  return await request.post('/user/register', { nickname, phone,password }) // 假设响应的数据在 response.data 中
}

export const userLoginService = async (phone, password) => {
  return await request.post('/user/login', { phone, password})
}

export const userGetInfoService = async () => request.get('/my/userinfo')

export const userGetFollowService = async () => request.get('/userinfo/getfollow')

export const userGetUserInfoService = async (id) => request.get(`/user/getuserinfo/${id}`)
export const updateUserInfoService = async (userId, updateData) => {
  // 路径中替换 userId，请求体传入完整的 updateData
  return await request.post(`/user/user/${userId}`, updateData);
};

// 新增：上传头像
export const uploadAvatarService = async (file, type) => {
  const formData = new FormData();
  formData.append('file', file);      // 字段名与后端保持一致（后端用@RequestParam("file")）
  formData.append('type', type);      // 添加必需的type参数

  return await request.post('/common/upload', formData, {
  });
};
export const userGetPassword = async (id) => request.get(`/user/password/${id}`)
export const checkPassword  = async (newp,old)=>request.post(`/user/check/${newp}/check1/${old}`);
